import { Injectable } from '@angular/core'
import { Observable, Subject } from "rxjs";
import {GeoJsonLayer,GeoData,ToolsTreeNode,LayerItem} from '../data_model/data-model'
@Injectable()
export class DataTransmissionService {
    //传输文件
    private FileSubject = new Subject<any>();
    //传输geoJson
    private GeoJsonSubject = new Subject<any>();
    //传输dataid，用于显示图层或者隐藏图层
    private LayerIdSubject = new Subject<any>();
    //传输实例运行结束后的运行记录
    private ModelRunRecordSubject = new Subject<any>();
    //传输服务容器返回的数据id,用于生成layerlist
    private  RemoteDataSubject = new Subject<any>();
    //准备工作完成，tool-box的finish向tool-panel发送数据提交请求,并运行模型
    private ReadySubject = new Subject<any>();
    //返回工具输入的准备状态
    private PreparedStateSubject = new Subject<any>();
    //当鼠标右击，返回点击事件event
    private SettingTreeContextMenuSubject = new Subject<any>();
    //在编辑工具箱时，选中一个工具，向编辑面板发送节点内容
    private SelectedToolNodeSubject = new Subject<any>();
    //当工具箱有更新时，提醒各位订阅者更新
    private ToolsTreeUpdatedSubject = new Subject<any>();
    //删除图层
    private DeleteLayerSubject = new Subject<any>();
    //返回地图区域resize之后event
    private MapResizeSubject = new Subject<any>();
    //传输layers list中所有的数据
    private LayerListSubject = new Subject<Array<LayerItem>>();
    //发起请求
    private ReqAllLayerData = new Subject<any>();


    sendFile(file: File) {
        this.FileSubject.next(file);
    }
    sendGeoJson(geoJsonLayer:GeoJsonLayer){
        this.GeoJsonSubject.next(geoJsonLayer);
    }
    sendLayerId(LayerId:string){
        this.LayerIdSubject.next(LayerId);
    }
    sendModelRunRecord(modelRunRecord:string){
        this.ModelRunRecordSubject.next(modelRunRecord);
    }
    sendRemoteData(data:GeoData){
        this.RemoteDataSubject.next(data);
    }
    sendReadySubject(){
        this.ReadySubject.next();
    }
    sendPreparedStateSubject(prepared:boolean){
        this.PreparedStateSubject.next(prepared);
    }
    sendSettingTreeContextMenuSubject(event:MouseEvent){
        this.SettingTreeContextMenuSubject.next(event);
    }
    sendSelectedToolNodeSubject(TreeNode:ToolsTreeNode){
        this.SelectedToolNodeSubject.next(TreeNode);
    }
    sendToolsTreeUpdatedSubject(){
        this.ToolsTreeUpdatedSubject.next();
    }
    sendDeleteLayerSubject(LayerId:any){
        this.DeleteLayerSubject.next(LayerId);
    }
    sendMapResizeSubject(eventTarget:any){
        this.MapResizeSubject.next(eventTarget);
    }
    sendLayerListSubject(LayerArray:Array<LayerItem>){
        this.LayerListSubject.next(LayerArray);
    }
    sendReqAllLayerData(){
        this.ReqAllLayerData.next();
    }


    getFile(): Observable<any> {
        return this.FileSubject.asObservable();
    }
    getGeoJson():Observable<any>{
        return this.GeoJsonSubject.asObservable();
    }
    getLayerId():Observable<any>{
        return this.LayerIdSubject.asObservable();
    }
    getModelRunRecord():Observable<any>{
        return this.ModelRunRecordSubject.asObservable();
    }
    getRemoteData():Observable<GeoData>{
        return this.RemoteDataSubject.asObservable();
    }
    
    getReadySubject():Observable<any>{
        return this.ReadySubject.asObservable();
    }
    getPreparedStateSubject():Observable<any>{
        return this.PreparedStateSubject.asObservable();
    }
    getSettingTreeContextMenuSubject():Observable<MouseEvent>{
        return this.SettingTreeContextMenuSubject.asObservable();
    }
    getSelectedToolNodeSubject():Observable<ToolsTreeNode>{
        return this.SelectedToolNodeSubject.asObservable();
    }
    getToolsTreeUpdatedSubject():Observable<any>{
        return this.ToolsTreeUpdatedSubject.asObservable();
    }
    getDeleteLayerSubject():Observable<any>{
        return this.DeleteLayerSubject.asObservable();
    }
    getMapResizeSubject():Observable<any>{
        return this.MapResizeSubject.asObservable();
    }
    getLayerListSubject():Observable<Array<LayerItem>>{
        return this.LayerListSubject.asObservable();
    }
    getReqAllLayerData():Observable<any>{
        return this.ReqAllLayerData.asObservable();
    }


}